package org.example.journal_items.DTO;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Map;

@Schema(description = "通用响应结果")
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result<T> {
    @Schema(description = "响应状态码", example = "200")
    private int code;

    @Schema(description = "响应消息", example = "操作成功")
    private String message;

    @Schema(description = "响应数据")
    private T data;

    @Schema(description = "参数校验错误信息")
    private Map<String, String> errors; // 用于参数校验错误

    // 成功响应
    public static <T> Result<T> success(T data) {
        return new Result<>(200, "成功", data, null);
    }

    // 成功无数据响应
    public static Result<Void> success() {
        return new Result<>(200, "成功", null, null);
    }

    // 失败响应
    public static <T> Result<T> fail(int code, String message) {
        return new Result<>(code, message, null, null);
    }

    // 失败响应带错误详情
    public static <T> Result<T> fail(int code, String message, Map<String, String> errors) {
        return new Result<>(code, message, null, errors);
    }

}